// 下发任务后端不做层级逻辑判断，需要前端去掉不能提交的字段(web,host)
const formatSubmitData = (data, type) => {
	const submitData = JSON.parse(JSON.stringify(data));
	if (type === 'web') {
		if (submitData.trigger_type === 'manual') {
			// 去除频率
			delete submitData.content_settings.interval;
			delete submitData.security_event_settings.interval;
			delete submitData.ssl_settings.interval;
			delete submitData.vul_settings.interval;
			delete submitData.change_check_settings;
			// 单次无网站画像、模式、监测方式
			delete submitData.vul_settings.type;
			delete submitData.vul_settings.enableSitePortraitTriggerMonitor;
			delete submitData.vul_settings.collect.speed;
		}
		let prelogin = {
			site_login: submitData.prelogin.site_login,
			is_proxy_enabled: submitData.prelogin.is_proxy_enabled,
			is_http_auth_enabled: submitData.prelogin.is_http_auth_enabled,
			login_method: submitData.prelogin.login_method,
		};
		if (submitData.prelogin.site_login) {
			// 预登录
			const {
				login_form_action_url,
				login_form_postdata,
				login_json_action_url,
				login_json_postdata,
				request_cookie,
				request_http_headers,
			} = submitData.prelogin;
			if (submitData.prelogin.login_method === 'form') {
				prelogin = { ...prelogin, login_form_action_url, login_form_postdata };
			} else if (submitData.prelogin.login_method === 'json') {
				prelogin = { ...prelogin, login_json_action_url, login_json_postdata };
			} else if (submitData.prelogin.login_method === 'cookie') {
				prelogin = { ...prelogin, request_cookie };
			} else if (submitData.prelogin.login_method === 'headers') {
				prelogin = { ...prelogin, request_http_headers };
			}
		}
		if (submitData.prelogin.is_proxy_enabled) {
			// 代理服务器
			const {
				proxy_host,
				proxy_password,
				proxy_port,
				proxy_scheme,
				proxy_username,
			} = submitData.prelogin;
			prelogin = {
				...prelogin,
				proxy_host,
				proxy_password,
				proxy_port,
				proxy_scheme,
				proxy_username,
			};
		}
		if (submitData.prelogin.is_http_auth_enabled) {
			// HTTP认证
			const { http_auth_password, http_auth_username } = submitData.prelogin;
			prelogin = { ...prelogin, http_auth_password, http_auth_username };
		}
		submitData.prelogin = prelogin;
		if (submitData.trigger_type === 'schedule') {
			if (submitData.vul_settings.collect.type === 'increment') {
				// 全量监测
				delete submitData.vul_settings.collect.depth;
				delete submitData.vul_settings.collect.maxPage;
				delete submitData.vul_settings.collect.speed;
			} else {
				// 增量监测
				delete submitData.vul_settings.enableSitePortraitTriggerMonitor;
			}
		}
		if (submitData.content_settings.type === 'full') {
			// 内容全量监测
			delete submitData.content_settings.collect.includeUrl;
		} else {
			// 内容指定页面监测
			delete submitData.content_settings.collect.depth;
			delete submitData.content_settings.collect.maxPage;
		}
	} else if (type === 'host') {
		if (submitData.trigger_type === 'manual') {
			delete submitData.interval;
		}
	}
	return submitData;
};
export default formatSubmitData;
